package edu.imu.question.mapper;

import edu.imu.question.entity.PaperAnswer;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

public interface PaperAnswerMapper {

    @Delete("delete from paper_answer where paper_id=#{paperId}")
    int deleteByPaperId(Long paperId);

    @Insert("insert into paper_answer(" +
            "id,paper_id,question_id,answer) " +
            "value(#{id},#{paperId},#{questionId},#{answer})")
    @Options(keyProperty = "id",useGeneratedKeys = true)
    int insert(PaperAnswer pa);

    @Select("select id,paper_id as paperId," +
            "question_id as questionId," +
            "answer from paper_answer where paper_id=#{paperId} and question_id=#{questionId}")
    PaperAnswer findByPaperIdAndQuestionId(long paperId, long questionId);
}
